package StringTest;

import java.util.Scanner;

public class Demo1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        challenge(sc.nextLine());
    }
    public static  void challenge(String s){
        if(s.length()>9 || s == null){
            return;
        }
        /*for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)>='1' && s.charAt(i)<='9')
           rule(s.charAt(i));
        }*/
        s.chars().filter(c->c>='1' && c<='9').forEach(b -> rule((char)b));
        //利用stream流简化字符串的过滤操作和遍历操作
    }
    public static void rule(char b){
        //可以用switch代替if-else
        if(b == '0'){
            System.out.println(Num.NONE.getMessage());
        } else if (b == '1') {
            System.out.println(Num.ONE.getMessage());
        } else if (b == '2') {
            System.out.println(Num.TWO.getMessage());
        } else if (b == '3') {
            System.out.println(Num.THREE.getMessage());
        } else if (b == '4') {
            System.out.println(Num.FOUR.getMessage());
        } else if (b == '5') {
            System.out.println(Num.FIVE.getMessage());
        } else if (b == '6') {
            System.out.println(Num.SIX.getMessage());
        } else if (b == '7') {
            System.out.println(Num.SEVEN.getMessage());
        } else if (b == '8') {
            System.out.println(Num.EIGHT.getMessage());
        } else if (b == '9') {
            System.out.println(Num.NINE.getMessage());
        }
    }
    private enum Num{
        NONE(" "),
        ONE("I"),
        TWO("II"),
        THREE("III"),
        FOUR("IV"),
        FIVE("V"),
        SIX("VI"),
        SEVEN("VII"),
        EIGHT("VIII"),
        NINE("IX");
        private final String message;
        Num(String message) {
            this.message = message;
        }
        public String getMessage() {
            return message;
        }
    }
}
